// ****************************************************************
// Copyright 2012, Stephan Burguchev
// e-mail: me@sburg.net
// ****************************************************************
// *
using System;
using System.IO;
using System.Security.AccessControl;
using NUnit.Framework;
using Updater.Utils;

namespace Updater.Tests
{
    [TestFixture]
    public class FileSystemTests
    {
        private TempDirectory tempDirectory;

        [Test]
        public void CheckForFullControlOnDirectory_TestOnSystemDir()
        {
            bool p = FileSystem.CheckForFileSystemRightsOnDirectory(
                Environment.GetFolderPath(Environment.SpecialFolder.System), FileSystemRights.FullControl);
            Assert.False(p);
        }

        [Test]
        public void CheckForFullControlOnDirectory_TestOnTempDir()
        {
            bool p = FileSystem.CheckForFileSystemRightsOnDirectory(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), FileSystemRights.FullControl);
            Assert.True(p);
        }

        [Test]
        public void CopyDirectory_Test()
        {
            string testDir = Path.Combine(Config.TestDataDirectory, "TestSubdir");
            FileSystem.CopyDirectory(testDir, this.tempDirectory, true);

            Assert.True(File.Exists(Path.Combine(testDir, "empty-1.data")));
            Assert.True(File.Exists(Path.Combine(testDir, "empty-2.data")));
            Assert.True(Directory.Exists(Path.Combine(testDir, "TestSubdir2")));
            Assert.AreEqual(3, Directory.GetFileSystemEntries(this.tempDirectory, "*", SearchOption.TopDirectoryOnly).Length);
            Assert.True(File.Exists(Path.Combine(testDir, "TestSubdir2\\1kb.data")));
            Assert.True(File.Exists(Path.Combine(testDir, "TestSubdir2\\512kb.data")));
            Assert.AreEqual(2, Directory.GetFiles(Path.Combine(this.tempDirectory, "TestSubdir2")).Length);
        }

        [SetUp]
        public void SetUp()
        {
            this.tempDirectory = new TempDirectory();
        }

        [TearDown]
        public void TearDown()
        {
            this.tempDirectory.Dispose();
        }
    }
}
